package com.bzs.batch.reconcile.batch.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bzs.batch.reconcile.batch.listener.ReadListener;
import com.bzs.batch.reconcile.batch.step.ConStep;
import com.bzs.batch.reconcile.entity.SysTransactionflow;
import com.bzs.batch.reconcile.mapper.SysTransactionflowMapper;
import lombok.AllArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @Classname ConJob
 * @Author baozs
 * @Date 2021/12/20 23:46
 * @Version 1.0
 * @Description
 **/
@Configuration
@AllArgsConstructor
public class ConJob {
    private final JobBuilderFactory jobBuilderFactory;
    private final ConStep conStep;
    private final ReadListener readListener;


    @Bean
    public Job getAConJob(){
        return jobBuilderFactory.get("getAConJob")
                //设置每次启动生成新的ID 即每次都被作为新的job来启动
                .incrementer(new RunIdIncrementer())
                .start(conStep.getAConStep())
                .listener(readListener)
                .build();
    }

    @Bean
    public Job getSysTransJob() throws Exception {
        return jobBuilderFactory.get("getSysTransJob")
                .incrementer(new RunIdIncrementer())
                .start(conStep.getSysStep())
                .listener(getSysListener())
                .build();
    }

    private JobExecutionListener getSysListener() {

        return new JobExecutionListener() {
            @Override
            public void beforeJob(JobExecution jobExecution) {

            }

            @Override
            public void afterJob(JobExecution jobExecution) {

            }
        };
    }
}
